package com.lap.auth.configure;

import com.lap.auth.filter.AuthenticationFilter;
import com.lap.auth.filter.AuthorizationFilter;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class FilterConfiguration {

  @Resource private AuthenticationFilter authenticationFilter;

  @Resource private AuthorizationFilter authorizationFilter;

  @Bean
  FilterRegistrationBean<AuthenticationFilter> authenticationFilterRegistration() {
    FilterRegistrationBean<AuthenticationFilter> registration = new FilterRegistrationBean<>();
    registration.setFilter(authenticationFilter);
    registration.addUrlPatterns("/*");
    registration.setName("authenticationFilter");
    registration.setOrder(1); // 认证过滤器
    return registration;
  }

  @Bean
  FilterRegistrationBean<AuthorizationFilter> authorizationFilterRegistration() {
    FilterRegistrationBean<AuthorizationFilter> registration = new FilterRegistrationBean<>();
    registration.setFilter(authorizationFilter);
    registration.addUrlPatterns("/*");
    registration.setName("authorizationFilter");
    registration.setOrder(2); // 授权过滤器
    return registration;
  }
}
